package servlet;

import dao.Db;
import model.User;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import java.io.IOException;

@WebServlet("/updateOk")
public class UpdateOk extends HttpServlet {
    @Override
    public void service(ServletRequest req, ServletResponse res)throws ServletException, IOException{
        //设置编码
        req.setCharacterEncoding("UTF-8");
        res.setContentType("text/html;charset=UTF-8");
        //收参
        Integer id=Integer.valueOf(req.getParameter("id"));
        String username=req.getParameter("username");
        String password=req.getParameter("password");
        String birthday=req.getParameter("birthday");
        //访问数据层
        User user=new User(id,username,password,birthday);
        Db db = new Db();
        int i=db.updateOneData(user);
        if (i>0){
            //跳转
            req.getRequestDispatcher("showlist").forward(req,res);
        }
    }
}